import java.util.ArrayList;
import java.util.List;
import java.util.Random;

class Card{
    private int rank;//数字
    private String suit;//花色

    public Card(String suit, int rank) {
        this.suit = suit;
        this.rank = rank;
    }

    public int getRank() {
        return rank;
    }

    public void setRank(int rank) {
        this.rank = rank;
    }

    public String getSuit() {
        return suit;
    }

    public void setSuit(String suit) {
        this.suit = suit;
    }

    @Override
    public String toString() {
        return "[" + this.suit + ":" + this.rank + "]";
    }
}

public class CardDemo {

    public static final String[] suits = {"♥", "♠", "♣", "♦"};

    //构建一副牌
    public static List<Card> buyCard(){
        ArrayList<Card> cards = new ArrayList<>();
        for (int i = 0; i < 4; i++){
            for (int j = 1; j <= 13; j++) {
                cards.add(new Card(suits[i], j));
            }
        }
        return cards;
    }

    //洗牌
    private static void swap(List<Card> cards, int i, int j){
        Card tmp = cards.get(i);
        cards.set(i, cards.get(j));
        cards.set(j, tmp);
    }
    public static void shuffle(List<Card> cards){
        for (int i = cards.size() - 1; i > 0; i--) {
            Random random = new Random();
            int rand = random.nextInt(i);
            swap(cards, i, rand);
        }
    }

    public static void main(String[] args) {
        List<Card> cards = buyCard();
        System.out.println("买牌：" + cards);
        shuffle(cards);
        System.out.println("洗牌：" + cards);

        //这本质上就是一个二维数组，存放hand用
        ArrayList<List<Card>> hand = new ArrayList<>();

        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();

        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);

        //每个人五张牌,一次一张
        for (int i = 0; i < 17; i++) {//大家都是第i张
            for (int j = 0; j < 3; j++) {//第j个人拿第i张
                Card card = cards.remove(0);//每次拿牌顶的第一张
                hand.get(j).add(card);//每个人轮流摸一张
            }
        }

        System.out.println("第一个人的牌：" + hand1);
        System.out.println("第二个人的牌：" + hand2);
        System.out.println("第三个人的牌：" + hand3);
        System.out.println("剩余的牌：" + cards);
    }
}